package org.jsola.hr.constant;

import org.jsola.core.validator.IConst;
import org.jsola.json.JsonKit;

import java.util.HashMap;
import java.util.Map;

/**
 * 任职受雇从业类型
 *
 * @author zhr
 */
public enum EmploymentTypeEnum implements IConst {

    /**
     * 雇员
     */
    雇员("1","雇员"),
    /**
     * 保险营销员
     */
    保险营销员("2","保险营销员"),
    /**
     * 证券经纪人
     */
    证券经纪人("3","证券经纪人"),
    /**
     * 实习学生（全日制学历教育）
     */
    实习学生_全日制学历教育("4","实习学生（全日制学历教育）"),
    /**
     * 其他
     */
    其他("5","其他");

    private final String value;
    private final String desc;
    /**
     * 枚举值罗列，给swagger接口文档展示用
     */
    public static final String VALUES_STR = "1,2,3,4,5";

     /**
     * 缓存所有value
     */
    private static final Map<String, EmploymentTypeEnum> LOOKUP = new HashMap<>();

    static {
        for (EmploymentTypeEnum e : EmploymentTypeEnum.values()) {
            LOOKUP.put(e.value, e);
        }
    }


    EmploymentTypeEnum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    /**
     * 根据value查找EmploymentTypeEnum
     * @param value value
     * @return EmploymentTypeEnum
     */
    public static EmploymentTypeEnum find(String value) {
        return LOOKUP.get(value);
    }

    /**
     * 根据desc查找EmploymentTypeEnum
     * @param desc desc
     * @return EmploymentTypeEnum
     */
    public static EmploymentTypeEnum findByDesc(String desc){
        for (EmploymentTypeEnum e : EmploymentTypeEnum.values()) {
            if(e.getDesc().equals(desc)){
                return e;
            }
        }
        return null;
    }

    /**
     * 所有枚举转json
     * @return json
     */
    public static String getAllToJson() {
        Map<String,Object> map = new HashMap<>();
        for (EmploymentTypeEnum e : EmploymentTypeEnum.values()) {
            map.put("value", e.value);
            map.put("desc", e.desc);
        }
        return JsonKit.toJSONString(map);
    }

    @Override
    public boolean check(Object obj) {
        String value = (String) obj;
        return find(value) != null;
    }

    public String getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }
}
